home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / PartMaker 4.3 / IdleTasks.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-12  |  3.0 KB  |  121 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        IdleTasks.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19. /* This function is called when a null event is received.  Do appropriate tasks
  20. ** for null event situations, such as handling balloon help for window. */
  21.  
  22.  
  23.  
  24. /*****************************************************************************/
  25.  
  26.  
  27.  
  28. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  29. #include "App.defs.h"        /* Get various application definitions.            */
  30. #include "App.protos.h"        /* Get the prototypes for application.            */
  31.  
  32.  
  33.  
  34. /*****************************************************************************/
  35. /*****************************************************************************/
  36.  
  37. #ifdef applec
  38. #pragma segment IdleTasks
  39. #endif
  40.  
  41. extern Boolean        gDocCreated;
  42.  
  43.  
  44.  
  45. /*****************************************************************************/
  46. /*****************************************************************************/
  47.  
  48.  
  49.  
  50. void    DoIdleTasks(EventRecord *event)
  51. {
  52. #ifndef __MWERKS__
  53. #pragma unused (event)
  54. #endif
  55.  
  56.     EventRecord        evt;
  57.     WindowPtr        window;
  58.     TEHandle        te;
  59.     Rect            rr;
  60.     KeyMap            kk;
  61.     short            mm, oldRes;
  62.     FileRecHndl        frHndl;
  63.     static short    gStartup = 2;
  64.  
  65.     if (TSMTEAvailable()) TSMEvent(event);
  66.  
  67.     GetKeys(kk);
  68.     mm  = (kk[1] & 0x8000) ? (cmdKey    ) : 0;
  69.     mm |= (kk[1] & 0x0004) ? (optionKey ) : 0;
  70.     mm |= (kk[1] & 0x0008) ? (controlKey) : 0;
  71.     mm |= (kk[1] & 0x0001) ? (shiftKey  ) : 0;
  72.     evt.what      = nullEvent;        /* Make valid null event, with modifiers. */
  73.     evt.modifiers = mm;
  74.  
  75.     frHndl = GetNextDocument(nil, 'PtMd');
  76.     PrepDocResFile(frHndl, &oldRes, fsRdPerm);
  77.     IsCtlEvent(nil, &evt, nil, nil);
  78.  
  79.     window = CTETargetInfo(&te, &rr);
  80.     if (window) {
  81.         if (rr.left < -8192)        /* If TextEdit control is in the frame...  */
  82.             BeginFrame(window);        /* Set clipping to the frame area.           */
  83.         else
  84.             BeginContent(window);    /* Else set clipping to the document area. */
  85.         CTEIdle();
  86.         EndContent(window);            /* EndContent can be used to close a BeginFrame. */
  87.     }
  88.  
  89.     if (!gDocCreated)
  90.         OpenDocumentWindow(&frHndl, nil, fsRdPerm);
  91.  
  92.     gDocCreated = true;
  93. }
  94.  
  95.  
  96.  
  97. OSErr    PrepDocResFile(FileRecHndl frHndl, short *oldRes, char perm)
  98. {
  99.     WindowPtr    ww;
  100.     FileRecHndl    ff;
  101.     OSErr        err;
  102.  
  103.     err = noErr;
  104.     for (ww = nil;;) {
  105.         ww = GetNextDocumentWindow(ww, 'PtMd');
  106.         if (!ww) break;
  107.         ff = (FileRecHndl)GetWRefCon(ww);
  108.         if (!ff) continue;
  109.         if (ff != frHndl) CloseDocResFile(ff);
  110.     }
  111.  
  112.     if (!frHndl) return(noErr);
  113.  
  114.     err = UseDocResFile(frHndl, oldRes, perm);
  115.  
  116.     return(err);
  117. }
  118.  
  119.  
  120.  
  121.